//
//  ServiceImformationCell.m
//  DingDongXiChe
//
//  Created by wtjr on 2017/11/28.
//  Copyright © 2017年 xieyingze. All rights reserved.
//

#import "ServiceImformationCell.h"
#import "CustomReuseCellView.h"

@interface ServiceImformationCell()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) CustomReuseCellView *serviceNameView;

@property (nonatomic, strong) CustomReuseCellView *serviceTimeView;

@property (nonatomic, strong) CustomReuseCellView *serviceDurationView;

@end

@implementation ServiceImformationCell

#pragma mark - ********************生命周期********************

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"ServiceImformationCell";
    ServiceImformationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[ServiceImformationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - 内部方法

- (void)initSubView {
    self.backgroundColor = kCOLOR_tableView;
    [self addSubview:self.mainView];
    [self.mainView addSubview:self.serviceNameView];
    [self.mainView addSubview:self.serviceTimeView];
    [self.mainView addSubview:self.serviceDurationView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0).insets(UIEdgeInsetsMake(5, 5, 5, 5));
    }];
    [self.serviceNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(@0);
        make.height.equalTo(@(kUI_CellHeight));
    }];
    [self.serviceTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.serviceNameView.mas_bottom);
        make.height.equalTo(self.serviceNameView);
    }];
    [self.serviceDurationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.serviceTimeView.mas_bottom);
        make.height.equalTo(self.serviceNameView);
    }];
}

#pragma mark - Setter

- (void)setViewModel:(OrderViewModel *)viewModel {
    _viewModel = viewModel;
    @weakify(self);
    [RACObserve(viewModel, order_packageName) subscribeNext:^(NSString *x) {
        @strongify(self);
        self.serviceNameView.value = x;
    }];
    [RACObserve(viewModel, order_packageTime) subscribeNext:^(NSString *x) {
        @strongify(self);
        self.serviceTimeView.value = x;
    }];
    [RACObserve(viewModel, order_packageDuration) subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        self.serviceDurationView.value = [NSString stringWithFormat:@"%ldmm",[x integerValue]];
    }];
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        [_mainView setViewShadow:kCOLOR_shadow offset:CGSizeMake(0, 0) radius:1];
    }
    return _mainView;
}

- (CustomReuseCellView *)serviceNameView {
    if (!_serviceNameView) {
        _serviceNameView = [CustomReuseCellView new];
        _serviceNameView.iconName = @"dd_package_package";
        _serviceNameView.title = @"服务套餐";
        _serviceNameView.value = @"套餐";
        _serviceNameView.showLine = YES;
    }
    return _serviceNameView;
}

- (CustomReuseCellView *)serviceTimeView {
    if (!_serviceTimeView) {
        _serviceTimeView = [CustomReuseCellView new];
        _serviceTimeView.iconName = @"dd_package_duration";
        _serviceTimeView.title = @"服务时间";
        _serviceTimeView.value = @"00:00";
        _serviceTimeView.showLine = YES;
    }
    return _serviceTimeView;
}

- (CustomReuseCellView *)serviceDurationView {
    if (!_serviceDurationView) {
        _serviceDurationView = [CustomReuseCellView new];
        _serviceDurationView.iconName = @"dd_package_duration";
        _serviceDurationView.title = @"服务时长";
        _serviceDurationView.value = @"00mm";
        _serviceDurationView.showLine = NO;
    }
    return _serviceDurationView;
}

@end
